home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-04-03 | 6.4 KB | 163 lines | [TEXT/MPS ] |
- // USegments.h
- // Copyright © 1995-96 by Apple Computer, Inc. All rights reserved.
-
- #ifndef __USEGMENTS__
- #define __USEGMENTS__
-
- // MacApp
-
- #ifndef __MACAPPTYPES__
- #include "MacAppTypes.h"
- #endif
-
- #if qSegments
-
- // Toolbox
-
- #ifndef __MEMORY__
- #include <Memory.h>
- #endif
-
- const ResType kCode = 'CODE'; // Resource type for code
-
- class CCodeSegment
- {
- public:
-
- Size GetSize();
- // GetSize returns the size, in bytes, of the segment
-
- void LoadMacAppSegment();
- // This function patches LoadSeg. It is called from the assembly-language routine
- // AMacAppLoadSeg, which is the actual patch setup by PatchTrap. AMacAppLoadSeg saves
- // registers and sets up the stack by 1) allocating space for LoadMacAppSegment's
- // result, and 2) pushing a copy of LoadSeg's parameter onto the stack for use by
- // LoadMacAppSegment. Signals failure if the segment could not be loaded.
- // NOTE: this routine requires the pascal keyword because it is called from assembler
- // code that assumes pascal parameter passing conventions.
-
- Boolean PreloadSegmentResource();
- // PreloadSegment is available to programmers who want to lock a segment at the top of
- // the heap without having to call a dummy procedure in that segment. It is also
- // useful for determining whether a segment can in fact be loaded before you try to
- // execute code in it. PreloadSegment returns true if the segment could be loaded,
- // false otherwise.
- // NOTE: this routine requires the pascal keyword because it is called from assembler
- // code that assumes pascal parameter passing conventions.
-
- void SetResidentSegment(Boolean makeResident);
- // SetResidentSegment can be used to make a segment resident (or no longer resident);
- // resident segments will not be unloaded by UnloadAllSegments; if a segment is made
- // resident, it is also preloaded.MacApp automatically marks its resident segment as
- // resident (the one containing the procedure CommandFromMenuItem); you probably should do
- // UnloadAllSegments before making a segment resident, to ensure that it is locked at
- // the top of the heap.
-
- Boolean IsSegmentLoaded();
- // Returns TRUE if the segment is loaded
-
- Handle GetSegResource();
-
- Boolean IsModelFar();
-
- #if qModelCFM
- Boolean IsModelCFM();
- #endif
-
- Ptr GetFirstFunctionPointer();
-
- void Unload();
- // Unload the segment
-
- Boolean ContainsAddress(void* address);
- // true if the (Loaded) segment contains the address
-
- short fSegNum; // the segment number
- Boolean fSegLoaderLoaded; // true if loaded in the segment loader sense
- Boolean fResidentSeg; // true if this seg should be resident
- Boolean fInTemporaryReserve; // true if this seg will be used in temporary reserve
- Boolean fCanUnload; // true if we ever allow unloading for this segment
- Handle fCodeSeg; // handle to the actual code segment
- long fSegSize; // size of the code segment
- CCodeSegment* fNextCodeSegment; // next segment in the linked list of segments
-
- #if qDebug
- static unsigned long gHighWater; // the largest amount of segments ever in memory
- Boolean fHighWater; // true if this segment was present at a high-water mark
- Boolean fEverLoaded; // true if this segment was ever loaded
- #endif
- };
-
- //----------------------------------------------------------------------------------------
- // Global variable declarations.
- //----------------------------------------------------------------------------------------
-
- extern CCodeSegment* gCodeSegs;
- // Code segment records for all the code segments
-
- extern Boolean gUnloadAllSegs;
- // UnloadAllSegments doesn't unload segments if this flag is false.
-
- //----------------------------------------------------------------------------------------
- // These global variable declarations are meant to be private but are in the interface
- // just in case.
- //----------------------------------------------------------------------------------------
-
- extern short pOldResFile;
- // The res file reference saved across segloads
-
- extern Boolean pLoadSegCalledFromOwnApp;
- // True if calling LoadMacAppSeg from the app and not from a _DA_ in our own heap.
- // (wheels within wheels for Pete's sake!)
-
- extern short pMaxSegNum;
- // The maximum segment number
-
-
- //----------------------------------------------------------------------------------------
- // Initialization
- //----------------------------------------------------------------------------------------
-
- void InitUSegments();
- // Initializes this unit.
-
- CCodeSegment* GetUnloadedCodeSegment(ProcPtr aProc);
- // GetSegNumber returns the CCodeSegment in which aProc resides.
-
- CCodeSegment* GetLoadedCodeSegment(void* address);
- // Given an address, return the loaded CCodeSegment that contains it.
-
- pascal UniversalProcPtr LoadMacAppSegment(short segnum);
- // This function patches LoadSeg. It is called from the assembly-language routine
- // AMacAppLoadSeg, which is the actual patch setup by PatchTrap. AMacAppLoadSeg saves
- // registers and sets up the stack by 1) allocating space for LoadMacAppSegment's
- // result, and 2) pushing a copy of LoadSeg's parameter onto the stack for use by
- // LoadMacAppSegment. Signals failure if the segment could not be loaded.
- // NOTE: this routine requires the pascal keyword because it is called from assembler
- // code that assumes pascal parameter passing conventions.
-
- pascal Boolean PreloadSegmentResource(short segnum);
- // PreloadSegment is available to programmers who want to lock a segment at the top of
- // the heap without having to call a dummy procedure in that segment. It is also
- // useful for determining whether a segment can in fact be loaded before you try to
- // execute code in it. PreloadSegment returns true if the segment could be loaded,
- // false otherwise.
- // NOTE: this routine requires the pascal keyword because it is called from assembler
- // code that assumes pascal parameter passing conventions.
-
- void LoadResidentSegments();
- // Makes resident the segments whose names are included in any 'res!' resources.
-
- void UnloadAllSegments(Boolean andPurge = FALSE);
- // UnloadAllSegments unloads all segments except the blank segment or the ones marked
- // resident. It is called at each iteration of the main event loop to compact memory,
- // as well as other places where compacting memory is needed or desirable.
- // Pass true for andPurge to purge the segments too.
-
- Size AddSegSizes(Handle segRsrcCounted);
- // Returns the total size of the code segments whose names are in the CString list
- // segRrsc.
-
- #endif // qSegments
- #endif // __USEGMENTS__
-